package com.lc.qianrenshiye.widget;

import android.content.Context;
import android.os.Handler;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

/**
 * Created by Administrator on 2016/12/7.
 */
public class MyViewPager extends ViewPager{

    private Handler handler;
    private boolean result;

    public void setHandler (Handler handler) {

        this.handler = handler;
    }

    public void setCanScroll (boolean scroll) {

        this.result = scroll;

    }

    public MyViewPager(Context context)
    {
        super(context);
        // TODO Auto-generated constructor stub
    }

    public MyViewPager(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:

                handler.removeCallbacksAndMessages(null);

            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_CANCEL:
                break;
            case MotionEvent.ACTION_UP:

                handler.sendEmptyMessageDelayed(1, 3000);

                break;
        }

        if (result)

            return super.onTouchEvent(ev);

        else

            return false;

    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {

        if (result)

            return super.onInterceptTouchEvent(ev);

        else

            return false;

    }



    //    @Override
//    protected boolean canScroll(View v, boolean checkV, int dx, int x, int y){
//
//        return true;
//    }

}
